﻿
/// <reference path="../Common.js" />
/// <reference path="../../Scripts/jquery-1.7.1-vsdoc.js" />
$(document).ready(function () {

    ClearMsg("username");
    ClearMsg("pwd");
 
});

var userlogin =
{
    login: function () {

        var AccountLogin = $("#username").val();
        var pwd = $("#pwd").val();
        var Issave = 0;
        if ($("#saveweek").attr("checked") == 'undefined') {
            Issave = 1;
        }

        var EmailIsTrueFlase = (/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/);
        if (!EmailIsTrueFlase.test(AccountLogin)) {
            ShowMsg("username", "邮箱格式不正确");
            return;
        }
        if (pwd.length < 6) {

            ShowMsg("pwd", "密码不能少于六位数");
            return;
        }


        $.ajax(
        {
            url: string.Format("/UserAPI/Login?Email={0}&Pwd={1}&IsSave={2}", AccountLogin, pwd, Issave), //请求验证页面
            type: "post", //请求方式 可换为post  注意验证页面接收方式

            contentType: "application/json;charset=utf-8",
            dataType: "json",
            success: function (data) {              // 请求成功后的回调  

                if (data.isSuccess) {
                    self.location = "/User";
                }
                else {
                    $.layer({ v_msgtype: 2, v_msg: data.Message });
                }

            },
            error: function (data) {                // 请求失败后的回调  
                alert(data);

            }
        })

    }
}